<include file="Public/head"/>
<body class="no-skin">
<include file="Public/header"/>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>    
 <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="__PUBLIC__/qwadmin/js/jquery-treegrid/jquery-ui-1.10.4.custom.min.js"></script>
<script src="__PUBLIC__/qwadmin/js/jquery-treegrid/jquery.tabelizer.js"></script>
 <link href="__PUBLIC__/qwadmin/js/jquery-treegrid/tabelizer.min.css" media="all" rel="stylesheet" type="text/css" />
    <include file="Public/sidebar"/>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <include file="Public/breadcrumbs"/>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">
                <include file="Public/set"/>

                <!-- /section:settings.box -->
                

                        <div class="row">
                            <div class="cf">
                                  
                                    <volist name="customer" id="v">
                                            <span class="btn btn-info" style="margin-top: 5px;margin-left: 5px;"><a href="{:U('index',array('shop_sites_id'=>$v['id']))}">{$v['shop_name']} </a></span>
                                     </volist>
                            </div>
                            <div class="col-sm-7">
					<div class="widget-box widget-color-green2">
							<div class="widget-header">
							<h4 class="widget-title lighter smaller">
							合作伙伴分类
							<span class="smaller-80">({$shop_name})</span>
							</h4>
						</div>

						<div class="widget-body">
							<div class="widget-main padding-8">
                                                            <ul id="tree2">
                                                                <input type="hidden" name="treedata" value="{json_encode( $list )}">
                                                            </ul>
							</div>
						</div>
					</div>
				</div>
                      
                          
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
              <h4 class="modal-title " id="myModalLabel">绑定</h4>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭</button>
              <button type="button" id="btn_submit" class="btn btn-primary tijiao" data-dismiss="modal"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>保存</button>
            </div>
          </div>
        </div>
  </div>
    <include file="Public/footer"/>
<include file="Public/footerjs"/>
</div><!-- /.main-container -->

	<script src="__PUBLIC__/qwadmin/js/fuelux/fuelux.tree.js"></script>
	<script src=__PUBLIC__/qwadmin/js/ace/elements.scroller.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/elements.colorpicker.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/elements.fileinput.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/elements.typeahead.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/elements.wysiwyg.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/elements.spinner.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/elements.treeview.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/elements.wizard.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/elements.aside.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/ace.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/ace.ajax-content.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/ace.touch-drag.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/ace.sidebar.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/ace.sidebar-scroll-1.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/ace.submenu-hover.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/ace.widget-box.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/ace.settings.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/ace.settings-rtl.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/ace.settings-skin.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/ace.widget-on-reload.js"></script>
		<script src="__PUBLIC__/qwadmin/js/ace/ace.searchbox-autocomplete.js"></script>


  <script id="select_option_list">
      {$select_option_list}
  </script>
  <script type="text/javascript">
      function edit(id,goods_type_id){
        var id = id;
        var goods_type_id=goods_type_id;
        $('.modal-body').html('');
      var   htm = '<div class="form-group">'+
                      '<input type="hidden" id="shop_type_id" value='+id+'>'+
                        '<label class="col-sm-3 control-label no-padding-right" for="form-field-10">中台站点类别 </label>'+
                            '<div class="col-sm-8">'+
                                '<select id="goods_type_id" name="goods_type_id" class="rcol-xs-10 col-sm-11">'+$('#select_option_list').html()+'</select>'+
                                '</div>'+
                           ' </div>';

        $(".modal-body").append(htm);
        $('#goods_type_id option').each(function(){
          if( goods_type_id == $(this).attr('value') ) {
              $(this).attr('selected' , true);
              return false;
          } 
       });
      $("#myModal").modal("show");
      }
      
      $(".tijiao").click(function(){
          
          var goods_type_id =  $('#goods_type_id option:selected').val();
          var id = $('#shop_type_id').val();
        
          $.post("{:U('edit')}", {id:id,goods_type_id:goods_type_id},function(data){
                if (data.errno == '0')
                {  
                    console.log(data);
                    var _self = $('#local_cat_' + data.id);
                    _self.find('span#status_info').html('已绑定分类:'+data.name+'&nbsp&nbsp');
                    _self.find('a').attr('href' , 'javascript:edit("'+id+'","'+goods_type_id+'")').text('重新绑定');
                    swal('','绑定成功' , 'success');
                    
//                    location.reload();
                } else {
                    swal('',data.error , 'success');
                    //G.ui.tips.err(data.error);
                }
            },'json');
      });
             
 </script>               
<script type="text/javascript">
			jQuery(function($){
	var sampleData = initiateDemoData();//see below

	$('#tree2').ace_tree({
		dataSource: sampleData['dataSource2'] ,
		loadingHTML:'<div class="tree-loading"><i class="ace-icon fa fa-refresh fa-spin blue"></i></div>',
		'open-icon' : 'ace-icon fa fa-folder-open',
		'close-icon' : 'ace-icon fa fa-folder',
		'itemSelect' : true,
		'folderSelect': true,
		'multiSelect': true,
		'selected-icon' : null,
		'unselected-icon' : null,
		'folder-open-icon' : 'ace-icon tree-plus',
		'folder-close-icon' : 'ace-icon tree-minus'
	});
	
	
	/**
	//Use something like this to reload data	
	$('#tree1').find("li:not([data-template])").remove();
	$('#tree1').tree('render');
	*/
	
	
	/**
	//please refer to docs for more info
	$('#tree1')
	.on('loaded.fu.tree', function(e) {
	})
	.on('updated.fu.tree', function(e, result) {
	})
	.on('selected.fu.tree', function(e) {
	})
	.on('deselected.fu.tree', function(e) {
	})
	.on('opened.fu.tree', function(e) {
	})
	.on('closed.fu.tree', function(e) {
	});
	*/
	
	
	function initiateDemoData(){
		var tree_data_2 = {
                    <foreach name="list" key="k" item="vo">
			<neq name="k" value="0">,</neq>'menus{$vo.shop_type_id}' : {text: '{:str_replace('\r\n','',trim($vo['name']))}  <span class="" style="float:right" id="local_cat_{$vo.id}" data-id="{$vo['id']}"><?php if(($vo['children']==0 && $vo['goods_name']) || (($vo['shop_sites_id']=='10001' || $vo['shop_sites_id']=='10002') && $vo['goods_name'] )):?><span id="status_info">已绑定:{$vo['goods_name']}</span> &nbsp&nbsp<a  href="javascript:edit(\'{$vo['id']}\',\'{$vo['goods_type_id']}\');" >重新绑定</a> <?php elseif($vo['children']==0 || $vo['shop_sites_id']=='10001' || $vo['shop_sites_id']=='10002'):?><span id="status_info"></span><a  href="javascript:edit(\'{$vo['id']}\',\'{$vo['goods_type_id']}\');" >绑定中台类别</a> <?php endif;?> ', type: '<empty name="vo.children">item<else/>folder</empty>', 'icon-class':'red'}
                    </foreach>
		}
                {$htmls}
		var dataSource2 = function(options, callback){
			var $data = null
			if(!("text" in options) && !("type" in options)){
				$data = tree_data_2;//the root tree
				callback({ data: $data });
				return;
			}
			else if("type" in options && options.type == "folder") {
				if("additionalParameters" in options && "children" in options.additionalParameters)
					$data = options.additionalParameters.children || {};
				else $data = {}//no data
			}
			
			if($data != null)//this setTimeout is only for mimicking some random delay
				setTimeout(function(){callback({ data: $data });} , parseInt(Math.random() * 500) + 200);

			//we have used static data here
			//but you can retrieve your data dynamically from a server using ajax call
			//checkout examples/treeview.html and examples/treeview.js for more info
		}

		
		return {'dataSource2': dataSource2 }
	}
        
   

    });
</script>
</body>
</html>
